#include "cpointerpeakdata.h"
//
CPointerPeakData::CPointerPeakData( const double * values,
		const QwtDoubleInterval * intervals, size_t size )
	:d_intervals( intervals ), d_values( values ), d_size( size )
{
}
//
QwtDoubleRect CPointerPeakData::boundingRect() const
{
	double minX, maxX, minY, maxY;
	minX = maxX = minY = maxY = 0.0;

	bool isValid = false;

	const size_t sz = size();
	for ( size_t i = 0; i < sz; i++ )
	{
		const QwtDoubleInterval intv = interval(i);
		if ( !intv.isValid() )
			continue;

		const double v = value(i);

		if ( !isValid )
		{
			minY = intv.minValue();
			maxY = intv.maxValue();
			minX = maxX = v;

			isValid = true;
		}
		else
		{
			if ( intv.minValue() < minY )
				minY = intv.minValue();
			if ( intv.maxValue() > maxY )
				maxY = intv.maxValue();

			if ( v < minX )
				minX = v;
			if ( v > maxX )
				maxX = v;
		}
	}
	if ( !isValid )
		return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid

	return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY);
}
//
